package com.china_goldcard.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.widget.BaseAdapter;

import java.util.List;

/**
 * 基础adpater
 */
public abstract class MyBaseAdapter<T> extends BaseAdapter {

    protected Context context;//运行上下文
    protected List<T> listData;//数据集合
    protected LayoutInflater listContainer;//视图容器
    protected int itemViewResource;//自定义项视图源id

    /**
     * 构造函数
     * @param context
     * @param data
     * @param resource
     */
    public MyBaseAdapter(Context context, List<T> data, int resource) {
        this.context = context;
        this.listContainer = LayoutInflater.from(context);	//创建视图容器并设置上下文
        this.itemViewResource = resource;
        this.listData = data;
    }

    /**
     * 重载
     * @param data
     */
    public void reloadData(List<T> data){
         this.listData = data;
         notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return listData.size();
    }

    @Override
    public T getItem(int index) {
        return listData.get(index);
    }

    @Override
    public long getItemId(int index) {
        return index;
    }
}
